#include "DriverDetail.h"

DriverDetail::DriverDetail(const char *pRootPath, const char *pIniUIFilename, const char *pIniDriverMappingFilename, const char *pIniVehiculeClassMappingFilename)
{
	initialized = false;
	rootPath = pRootPath; 
	iniDriverMappingFilename = pIniDriverMappingFilename;
	iniVehiculeClassMappingFilename = pIniVehiculeClassMappingFilename;

	nbProfiles = GetPrivateProfileInt("Profiles", "count", 0, pIniUIFilename);
	for (int i = 0 ; i < nbProfiles; i++) {
		sprintf(tmp, "Profile.%d", (i+1));
		profiles[i].widgetOffsetX = (signed int)GetPrivateProfileInt(tmp, "DriverPanel.offsetX", 0, pIniUIFilename);
		profiles[i].widgetOffsetY = (signed int)GetPrivateProfileInt(tmp, "DriverPanel.offsetY", 0, pIniUIFilename);
		profiles[i].hide = GetPrivateProfileInt(tmp, "DriverPanel.hide", 0, pIniUIFilename) != 0;
	}


	//std::string str = rootPath;
	GetPrivateProfileString("UI Widgets", "DriverPanel.ini", "", tmp, 999, pIniUIFilename);
	//str.append(tmp);
	sprintf(iniUIFilename, "%s%s", rootPath, tmp);
	//iniUIFilename = str.c_str(); //pIniUIFilename; 
	available = GetPrivateProfileInt("Driver Panel", "available", 0, iniUIFilename) != 0;
	
	mLastDriverName[0] = 0;

	mDriverNumStr[0] = 0;
	mDriverName[0] = 0;
	mDriverTeam[0] = 0;
	mClassName[0] = 0;
	mClassStickerName[0] = 0;
	mPlaceStr[0] = 0;

}

void DriverDetail::init(const ScreenInfoV01 &info, float ratio, float ratioWidth, float ratioHeight, Sprite spriteList[], Sprite logoList[], Sprite avatarList[]) {
	if (!available) {
		initialized = true;
		return;
	}

	for (int i = 0 ; i < nbProfiles; i++) {
		profiles[i].widgetOffsetX *= ratioWidth;
		profiles[i].widgetOffsetY *= ratioHeight;
	}


	int posX = (int)(ratioWidth * GetPrivateProfileInt("Driver Panel", "image.left", 40, iniUIFilename));//40;
	int posY = (int)(ratioHeight * GetPrivateProfileInt("Driver Panel", "image.top", 550, iniUIFilename));//550;

	//LPDIRECT3DDEVICE9 dev = static_cast<LPDIRECT3DDEVICE9>(info.mDevice);	
	
	useCategoryFontColorForNumber = GetPrivateProfileInt("Driver Panel", "use.category.font.color.for.car.number.field", 0, iniUIFilename) != 0;
	
	bgImageData.spriteIndex = GetPrivateProfileInt("Driver Panel", "image.id", 0, iniUIFilename) -1;
	if (bgImageData.spriteIndex > -1) {
		bgImageData.left = posX;
		bgImageData.top = posY;
		bgImageData.width = (int)(GetPrivateProfileInt("Driver Panel", "image.width", (int)spriteList[bgImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
		bgImageData.height = (int)(GetPrivateProfileInt("Driver Panel", "image.height", (int)spriteList[bgImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
		bgImageData.colorIndex = GetPrivateProfileInt("Driver Panel", "image.color.id", 1, iniUIFilename) -1;
	}
	
	// Driver Number
	numberAvailable = GetPrivateProfileInt("Driver Panel.Number", "available", 0, iniUIFilename) != 0;
	if (numberAvailable) {
		numberTextData.fontIndex = GetPrivateProfileInt("Driver Panel.Number", "text.font.id", 1, iniUIFilename) - 1;
		numberTextData.alignment = GetPrivateProfileInt("Driver Panel.Number", "text.alignment", 1, iniUIFilename);
		numberTextData.colorIndex = GetPrivateProfileInt("Driver Panel.Number", "text.font.color.id", 1, iniUIFilename) - 1;
		numberTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Panel.Number", "text.left", 0, iniUIFilename) * ratioWidth);
		numberTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Panel.Number", "text.top", 0, iniUIFilename) * ratioHeight);
		numberTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Panel.Number", "text.right", 100, iniUIFilename) * ratioWidth);
		numberTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Panel.Number", "text.bottom", 100, iniUIFilename) * ratioHeight);
	}


	// Driver Name
	nameAvailable = GetPrivateProfileInt("Driver Panel.Name", "available", 0, iniUIFilename) != 0;
	if (nameAvailable) {
		nameTextData.fontIndex = GetPrivateProfileInt("Driver Panel.Name", "text.font.id", 1, iniUIFilename) - 1;
		nameTextData.colorIndex = GetPrivateProfileInt("Driver Panel.Name", "text.font.color.id", 1, iniUIFilename) - 1;
		nameTextData.alignment = GetPrivateProfileInt("Driver Panel.Name", "text.alignment", 1, iniUIFilename);
		nameTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Panel.Name", "text.left", 0, iniUIFilename) * ratioWidth);
		nameTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Panel.Name", "text.top", 0, iniUIFilename) * ratioHeight);
		nameTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Panel.Name", "text.right", 100, iniUIFilename) * ratioWidth);
		nameTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Panel.Name", "text.bottom", 100, iniUIFilename) * ratioHeight);
	
		nameOriginalAvatarIndex = -1;
		nameAvatarData.spriteIndex = GetPrivateProfileInt("Driver Panel.Name", "avatar.id", 0, iniUIFilename) -1;
		if (nameAvatarData.spriteIndex > -1) {
			nameOriginalAvatarIndex = nameAvatarData.spriteIndex;
			nameAvatarData.left = (int)(posX + GetPrivateProfileInt("Driver Panel.Name", "avatar.left", 0, iniUIFilename) * ratioWidth);
			nameAvatarData.top = (int)(posY + GetPrivateProfileInt("Driver Panel.Name", "avatar.top", 0, iniUIFilename) * ratioHeight);
			nameAvatarData.width = (int)(GetPrivateProfileInt("Driver Panel.Name", "avatar.width", (int)avatarList[nameAvatarData.spriteIndex].width, iniUIFilename) * ratioWidth);
			nameAvatarData.height = (int)(GetPrivateProfileInt("Driver Panel.Name", "avatar.height", (int)avatarList[nameAvatarData.spriteIndex].height, iniUIFilename) * ratioHeight);
			nameAvatarData.colorIndex = GetPrivateProfileInt("Driver Panel.Name", "avatar.color.id", 1, iniUIFilename) -1;
		}
	}
	
	// driver place
	placeAvailable = GetPrivateProfileInt("Driver Panel.Place", "available", 0, iniUIFilename) != 0;
	if (placeAvailable) {
		//rctDriverPlace.left = spBackground->position.x + (202 + 2) * ratioWidth;
		//rctDriverPlace.top = spBackground->position.y + (18 + 4) * ratioHeight;
		//rctDriverPlace.right = spBackground->position.x + 236 * ratioWidth;
		//rctDriverPlace.bottom = spBackground->position.y + 57 * ratioHeight;
		placeTextData.fontIndex = GetPrivateProfileInt("Driver Panel.Place", "text.font.id", 1, iniUIFilename) - 1;
		placeTextData.alignment = GetPrivateProfileInt("Driver Panel.Place", "text.alignment", 1, iniUIFilename);
		placeTextData.colorIndex = GetPrivateProfileInt("Driver Panel.Place", "text.font.color.id", 1, iniUIFilename) - 1;
		placeTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Panel.Place", "text.left", 0, iniUIFilename) * ratioWidth);
		placeTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Panel.Place", "text.top", 0, iniUIFilename) * ratioHeight);
		placeTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Panel.Place", "text.right", 100, iniUIFilename) * ratioWidth);
		placeTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Panel.Place", "text.bottom", 100, iniUIFilename) * ratioHeight);


		firstPlaceAvailable =  GetPrivateProfileInt("Driver Panel.FirstAllCat", "available", 0, iniUIFilename) != 0;
		if (firstPlaceAvailable) {
			firstPlaceTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Panel.FirstAllCat", "text.left", -9999, iniUIFilename) * ratioWidth);
			firstPlaceTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Panel.FirstAllCat", "text.top", -9999, iniUIFilename) * ratioHeight);
			firstPlaceTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Panel.FirstAllCat", "text.right", -9999, iniUIFilename) * ratioWidth);
			firstPlaceTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Panel.FirstAllCat", "text.bottom", -9999, iniUIFilename) * ratioHeight);
			if (firstPlaceTextData.rect.left < 0) firstPlaceTextData.rect.left = placeTextData.rect.left;
			if (firstPlaceTextData.rect.top < 0) firstPlaceTextData.rect.top = placeTextData.rect.top;
			if (firstPlaceTextData.rect.right < 0 ) firstPlaceTextData.rect.right = placeTextData.rect.right;
			if (firstPlaceTextData.rect.bottom < 0) firstPlaceTextData.rect.bottom = placeTextData.rect.bottom;

			firstPlaceTextData.fontIndex = GetPrivateProfileInt("Driver Panel.FirstAllCat", "text.font.id", 1, iniUIFilename) - 1;
			firstPlaceTextData.colorIndex = GetPrivateProfileInt("Driver Panel.FirstAllCat", "text.font.color.id", 1, iniUIFilename) - 1;
			firstPlaceTextData.alignment = GetPrivateProfileInt("Driver Panel.FirstAllCat", "text.alignment", 1, iniUIFilename);

			firstPlaceImageData.spriteIndex = GetPrivateProfileInt("Driver Panel.FirstAllCat", "image.id", 0, iniUIFilename) -1;
			if (firstPlaceImageData.spriteIndex != -1) {
				firstPlaceImageData.left = (int)(posX + GetPrivateProfileInt("Driver Panel.FirstAllCat", "image.left", 0, iniUIFilename) * ratioWidth);
				firstPlaceImageData.top = (int)(posY + GetPrivateProfileInt("Driver Panel.FirstAllCat", "image.top", 0, iniUIFilename) * ratioHeight);
				firstPlaceImageData.width = (int)(GetPrivateProfileInt("Driver Panel.FirstAllCat", "image.width", (int)spriteList[firstPlaceImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
				firstPlaceImageData.height = (int)(GetPrivateProfileInt("Driver Panel.FirstAllCat", "image.height", (int)spriteList[firstPlaceImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
				firstPlaceImageData.colorIndex = GetPrivateProfileInt("Driver Panel.FirstAllCat", "image.color.id", 1, iniUIFilename) -1;
			}

		}

		firstPlaceInCatAvailable =  GetPrivateProfileInt("Driver Panel.FirstInCat", "available", 0, iniUIFilename) != 0;
		if (firstPlaceInCatAvailable) {
			firstPlaceInCatTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Panel.FirstInCat", "text.left", -9999, iniUIFilename) * ratioWidth);
			firstPlaceInCatTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Panel.FirstInCat", "text.top", -9999, iniUIFilename) * ratioHeight);
			firstPlaceInCatTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Panel.FirstInCat", "text.right", -9999, iniUIFilename) * ratioWidth);
			firstPlaceInCatTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Panel.FirstInCat", "text.bottom", -9999, iniUIFilename) * ratioHeight);
			if (firstPlaceInCatTextData.rect.left < 0) firstPlaceInCatTextData.rect.left = placeTextData.rect.left;
			if (firstPlaceInCatTextData.rect.top < 0) firstPlaceInCatTextData.rect.top = placeTextData.rect.top;
			if (firstPlaceInCatTextData.rect.right < 0 ) firstPlaceInCatTextData.rect.right = placeTextData.rect.right;
			if (firstPlaceInCatTextData.rect.bottom < 0) firstPlaceInCatTextData.rect.bottom = placeTextData.rect.bottom;

			firstPlaceInCatTextData.fontIndex = GetPrivateProfileInt("Driver Panel.FirstInCat", "text.font.id", 1, iniUIFilename) - 1;
			firstPlaceInCatTextData.colorIndex = GetPrivateProfileInt("Driver Panel.FirstInCat", "text.font.color.id", 1, iniUIFilename) - 1;
			firstPlaceInCatTextData.alignment = GetPrivateProfileInt("Driver Panel.FirstInCat", "text.alignment", 1, iniUIFilename);

			firstPlaceInCatImageData.spriteIndex = GetPrivateProfileInt("Driver Panel.FirstInCat", "image.id", 0, iniUIFilename) -1;
			if (firstPlaceInCatImageData.spriteIndex != -1) {
				firstPlaceInCatImageData.left = (int)(posX + GetPrivateProfileInt("Driver Panel.FirstInCat", "image.left", 0, iniUIFilename) * ratioWidth);
				firstPlaceInCatImageData.top = (int)(posY + GetPrivateProfileInt("Driver Panel.FirstInCat", "image.top", 0, iniUIFilename) * ratioHeight);
				firstPlaceInCatImageData.width = (int)(GetPrivateProfileInt("Driver Panel.FirstInCat", "image.width", (int)spriteList[firstPlaceInCatImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
				firstPlaceInCatImageData.height = (int)(GetPrivateProfileInt("Driver Panel.FirstInCat", "image.height", (int)spriteList[firstPlaceInCatImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
				firstPlaceInCatImageData.colorIndex = GetPrivateProfileInt("Driver Panel.FirstInCat", "image.color.id", 1, iniUIFilename) -1;
			}

		}

	} 

	// driver team
	teamAvailable = GetPrivateProfileInt("Driver Panel.Team", "available", 0, iniUIFilename) != 0;
	if (teamAvailable) {
		teamTextData.fontIndex = GetPrivateProfileInt("Driver Panel.Team", "text.font.id", 1, iniUIFilename) - 1;
		teamTextData.colorIndex = GetPrivateProfileInt("Driver Panel.Team", "text.font.color.id", 1, iniUIFilename) - 1;
		teamTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Panel.Team", "text.left", 0, iniUIFilename) * ratioWidth);
		teamTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Panel.Team", "text.top", 0, iniUIFilename) * ratioHeight);
		teamTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Panel.Team", "text.right", 100, iniUIFilename) * ratioWidth);
		teamTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Panel.Team", "text.bottom", 100, iniUIFilename) * ratioHeight);
		teamTextData.alignment = GetPrivateProfileInt("Driver Panel.Team", "text.alignment", 1, iniUIFilename);
	}

	// category
	classAvailable =  GetPrivateProfileInt("Driver Panel.Category", "available", 0, iniUIFilename) != 0;
	if (classAvailable) {
		classTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Panel.Category", "text.left", 0, iniUIFilename) * ratioWidth);
		classTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Panel.Category", "text.top", 0, iniUIFilename) * ratioHeight);
		classTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Panel.Category", "text.right", 100, iniUIFilename) * ratioWidth);
		classTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Panel.Category", "text.bottom", 100, iniUIFilename) * ratioHeight);

		classTextData.fontIndex = GetPrivateProfileInt("Driver Panel.Category", "text.font.id", 1, iniUIFilename) - 1;
		classTextData.colorIndex = GetPrivateProfileInt("Driver Panel.Category", "text.font.color.id", 1, iniUIFilename) - 1;
		classTextData.alignment = GetPrivateProfileInt("Driver Panel.Category", "text.alignment", 1, iniUIFilename);

		classImageData.spriteIndex = GetPrivateProfileInt("Driver Panel.Category", "image.id", 0, iniUIFilename) -1;
		if (classImageData.spriteIndex > -1) {
			classImageData.left = (int)(posX + GetPrivateProfileInt("Driver Panel.Category", "image.left", 0, iniUIFilename) * ratioWidth);
			classImageData.top = (int)(posY + GetPrivateProfileInt("Driver Panel.Category", "image.top", 0, iniUIFilename) * ratioHeight);
			classImageData.width = (int)(GetPrivateProfileInt("Driver Panel.Category", "image.width", (int)spriteList[classImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			classImageData.height = (int)(GetPrivateProfileInt("Driver Panel.Category", "image.height", (int)spriteList[classImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			classImageData.colorIndex = GetPrivateProfileInt("Driver Panel.Category", "image.color.id", 1, iniUIFilename) -1;
		}
		classOriginalImageColorIndex = classImageData.colorIndex;
		classOriginalTextColorIndex = classTextData.colorIndex;
	}


	// class name
	classOriginalLogoIndex = -1;
	classNameAvailable =  GetPrivateProfileInt("Driver Panel.ClassName", "available", 0, iniUIFilename) != 0;
	if (classNameAvailable) {
		classNameTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Panel.ClassName", "text.left", 0, iniUIFilename) * ratioWidth);
		classNameTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Panel.ClassName", "text.top", 0, iniUIFilename) * ratioHeight);
		classNameTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Panel.ClassName", "text.right", 100, iniUIFilename) * ratioWidth);
		classNameTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Panel.ClassName", "text.bottom", 100, iniUIFilename) * ratioHeight);

		classNameTextData.fontIndex = GetPrivateProfileInt("Driver Panel.ClassName", "text.font.id", 1, iniUIFilename) - 1;
		classNameTextData.colorIndex = GetPrivateProfileInt("Driver Panel.ClassName", "text.font.color.id", 1, iniUIFilename) - 1;
		classNameTextData.alignment = GetPrivateProfileInt("Driver Panel.ClassName", "text.alignment", 1, iniUIFilename);

		classLogoData.spriteIndex = GetPrivateProfileInt("Driver Panel.ClassName", "logo.id", 0, iniUIFilename) -1;
		if (classLogoData.spriteIndex > -1) {
			classOriginalLogoIndex = classLogoData.spriteIndex;
			classLogoData.left = (int)(posX + GetPrivateProfileInt("Driver Panel.ClassName", "logo.left", 0, iniUIFilename) * ratioWidth);
			classLogoData.top = (int)(posY + GetPrivateProfileInt("Driver Panel.ClassName", "logo.top", 0, iniUIFilename) * ratioHeight);
			classLogoData.width = (int)(GetPrivateProfileInt("Driver Panel.ClassName", "logo.width", (int)logoList[classLogoData.spriteIndex].width, iniUIFilename) * ratioWidth);
			classLogoData.height = (int)(GetPrivateProfileInt("Driver Panel.ClassName", "logo.height", (int)logoList[classLogoData.spriteIndex].height, iniUIFilename) * ratioHeight);
			classLogoData.colorIndex = GetPrivateProfileInt("Driver Panel.ClassName", "logo.color.id", 1, iniUIFilename) -1;
		}
	}

	
	initialized = true;
}


	void DriverDetail::updateData(const VehicleScoringInfoV01 &vinfo, const DriverInfo &di, TimingInfo & timingInCategory) {
		if (!available) return;

		memcpy(&mPlace, &vinfo.mPlace, 1);
		if (timingInCategory.bestPlaceID == vinfo.mID) {
			firstPlaceInCat = true;
		} else {
			firstPlaceInCat = false;
		}

		memset(&mPlaceStr[0], 0, 3); /* clear sockaddr structure */
		sprintf( mPlaceStr, "%d", mPlace);

		//if (memcmp(mLastDriverName, di.accountName, 32) != 0) {
		//	memcpy(&mLastDriverName, &di.accountName, 32);

			if (nameAvailable) {
				if (di.mNameAvatarIndex == -1) {
					nameAvatarData.spriteIndex = nameOriginalAvatarIndex;
				} else {
					nameAvatarData.spriteIndex = di.mNameAvatarIndex;
				}

				
				memcpy(&mDriverName, &di.mDriverName, 32);
			}

			if (numberAvailable) {
				memcpy(&mDriverNumStr, &di.mDriverNumStr, 5);
			}
			if (teamAvailable) {
				memcpy(&mDriverTeam, &di.mDriverTeam, 32);
			}

			if (classAvailable) {
				if (di.mCategoryTextColorIndex == -1) {
					classTextData.colorIndex = classOriginalTextColorIndex;
				} else {
					classTextData.colorIndex = di.mCategoryTextColorIndex;
				}
				if (useCategoryFontColorForNumber) {
					numberTextData.colorIndex = classTextData.colorIndex;
				}
				if (di.mCategoryImageColorIndex == -1) {
					classImageData.colorIndex = classOriginalImageColorIndex;
				} else {
					classImageData.colorIndex = di.mCategoryImageColorIndex;
				}
				
				memcpy(&mClassStickerName, &di.mCategoryName, 32);
			}
			if (classNameAvailable) {
				if (di.mClassLogoIndex == -1) {
					classLogoData.spriteIndex = classOriginalLogoIndex;
				} else {
					classLogoData.spriteIndex = di.mClassLogoIndex;
				}

				memcpy(&mClassName, &di.mClassName, 32);
			}
		//}
	}


void DriverDetail::render(int profileIndex, const ScreenInfoV01 &info, const LPD3DXFONT *fontList, const D3DCOLOR *colorList, Sprite spriteList[], Sprite logoList[], Sprite avatarList[]) { 
	if (!available) return;
	if (gReplayIsActive) return;
	if (profiles[profileIndex].hide) return;

	LPDIRECT3DDEVICE9 dev = static_cast<LPDIRECT3DDEVICE9>(info.mDevice);	
	if (bgImageData.spriteIndex > -1) {
		spriteList[bgImageData.spriteIndex].setPosition(bgImageData.left + profiles[profileIndex].widgetOffsetX, bgImageData.top + profiles[profileIndex].widgetOffsetY);
		spriteList[bgImageData.spriteIndex].setSize(bgImageData.width, bgImageData.height);
		spriteList[bgImageData.spriteIndex].render(dev, colorList[bgImageData.colorIndex], 100);
	}
	if (placeAvailable) {
		if (mPlace == 1 && firstPlaceAvailable) {
			if (firstPlaceImageData.spriteIndex != -1) {
				spriteList[firstPlaceImageData.spriteIndex].setPosition(firstPlaceImageData.left + profiles[profileIndex].widgetOffsetX, firstPlaceImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[firstPlaceImageData.spriteIndex].setSize(firstPlaceImageData.width, firstPlaceImageData.height);
				spriteList[firstPlaceImageData.spriteIndex].render(dev, colorList[firstPlaceImageData.colorIndex], 100);
			}
			tmpRect.left = firstPlaceTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = firstPlaceTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = firstPlaceTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = firstPlaceTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[firstPlaceTextData.fontIndex]->DrawTextA(NULL, mPlaceStr, -1, &tmpRect, firstPlaceTextData.alignment, colorList[firstPlaceTextData.colorIndex]);
		} else if (firstPlaceInCat && firstPlaceInCatAvailable) {
			if (firstPlaceInCatImageData.spriteIndex != -1) {
				spriteList[firstPlaceInCatImageData.spriteIndex].setPosition(firstPlaceInCatImageData.left + profiles[profileIndex].widgetOffsetX, firstPlaceInCatImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[firstPlaceInCatImageData.spriteIndex].setSize(firstPlaceInCatImageData.width, firstPlaceInCatImageData.height);
				spriteList[firstPlaceInCatImageData.spriteIndex].render(dev, colorList[firstPlaceInCatImageData.colorIndex], 100);
			}
			tmpRect.left = firstPlaceInCatTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = firstPlaceInCatTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = firstPlaceInCatTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = firstPlaceInCatTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[firstPlaceInCatTextData.fontIndex]->DrawTextA(NULL, mPlaceStr, -1, &tmpRect, firstPlaceInCatTextData.alignment, colorList[firstPlaceInCatTextData.colorIndex]);
		} else {
			tmpRect.left = placeTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = placeTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = placeTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = placeTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[placeTextData.fontIndex]->DrawTextA(NULL, mPlaceStr, -1, &tmpRect, placeTextData.alignment, colorList[placeTextData.colorIndex]);
		}
	} 
	
	
	if (nameAvailable) {
		if (nameAvatarData.spriteIndex != -1) {
			avatarList[nameAvatarData.spriteIndex].setPosition(nameAvatarData.left + profiles[profileIndex].widgetOffsetX, nameAvatarData.top + profiles[profileIndex].widgetOffsetY);
			avatarList[nameAvatarData.spriteIndex].setSize(nameAvatarData.width, nameAvatarData.height);
			avatarList[nameAvatarData.spriteIndex].render(dev, colorList[nameAvatarData.colorIndex], 100);
		}
		
		tmpRect.left = nameTextData.rect.left + profiles[profileIndex].widgetOffsetX;
		tmpRect.top = nameTextData.rect.top + profiles[profileIndex].widgetOffsetY;
		tmpRect.right = nameTextData.rect.right + profiles[profileIndex].widgetOffsetX;
		tmpRect.bottom = nameTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
		fontList[nameTextData.fontIndex]->DrawTextA(NULL, mDriverName, -1, &tmpRect, nameTextData.alignment, colorList[nameTextData.colorIndex]);
	}

	if (teamAvailable) {
		tmpRect.left = teamTextData.rect.left + profiles[profileIndex].widgetOffsetX;
		tmpRect.top = teamTextData.rect.top + profiles[profileIndex].widgetOffsetY;
		tmpRect.right = teamTextData.rect.right + profiles[profileIndex].widgetOffsetX;
		tmpRect.bottom = teamTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
		fontList[teamTextData.fontIndex]->DrawTextA(NULL, mDriverTeam, -1, &tmpRect, teamTextData.alignment, colorList[teamTextData.colorIndex]);
	}

	// category
	if (classAvailable) {
		if (classImageData.spriteIndex != -1) {
			spriteList[classImageData.spriteIndex].setPosition(classImageData.left + profiles[profileIndex].widgetOffsetX, classImageData.top + profiles[profileIndex].widgetOffsetY);
			spriteList[classImageData.spriteIndex].setSize(classImageData.width, classImageData.height);
			spriteList[classImageData.spriteIndex].render(dev, colorList[classImageData.colorIndex], 100);
		}
		tmpRect.left = classTextData.rect.left + profiles[profileIndex].widgetOffsetX;
		tmpRect.top = classTextData.rect.top + profiles[profileIndex].widgetOffsetY;
		tmpRect.right = classTextData.rect.right + profiles[profileIndex].widgetOffsetX;
		tmpRect.bottom = classTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
		fontList[classTextData.fontIndex]->DrawTextA(NULL, mClassStickerName, -1, &tmpRect, classTextData.alignment, colorList[classTextData.colorIndex]);
	}
	// class name
	if (classNameAvailable) {
		if (classLogoData.spriteIndex != -1) {
			logoList[classLogoData.spriteIndex].setPosition(classLogoData.left + profiles[profileIndex].widgetOffsetX, classLogoData.top + profiles[profileIndex].widgetOffsetY);
			logoList[classLogoData.spriteIndex].setSize(classLogoData.width, classLogoData.height);
			logoList[classLogoData.spriteIndex].render(dev, colorList[classLogoData.colorIndex], 100);
		}
		
		tmpRect.left = classNameTextData.rect.left + profiles[profileIndex].widgetOffsetX;
		tmpRect.top = classNameTextData.rect.top + profiles[profileIndex].widgetOffsetY;
		tmpRect.right = classNameTextData.rect.right + profiles[profileIndex].widgetOffsetX;
		tmpRect.bottom = classNameTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
		fontList[classNameTextData.fontIndex]->DrawTextA(NULL, mClassName, -1, &tmpRect, classNameTextData.alignment, colorList[classNameTextData.colorIndex]);

	}

	if (numberAvailable) {
		tmpRect.left = numberTextData.rect.left + profiles[profileIndex].widgetOffsetX;
		tmpRect.top = numberTextData.rect.top + profiles[profileIndex].widgetOffsetY;
		tmpRect.right = numberTextData.rect.right + profiles[profileIndex].widgetOffsetX;
		tmpRect.bottom = numberTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
		fontList[numberTextData.fontIndex]->DrawTextA(NULL, mDriverNumStr, -1, &tmpRect, numberTextData.alignment, colorList[numberTextData.colorIndex]);
	}
}



DriverDetail::~DriverDetail(void)
{
}
